home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / PowerPlant / Temperature / CMainWindow.cp < prev    next >
Encoding:
Text File  |  1998-10-11  |  4.9 KB  |  225 lines  |  [TEXT/CWIE]

  1. // CMainWindow.cp -- window methods
  2.  
  3. #include "CMainWindow.h"
  4.  
  5. #include <UEnvironment.h>
  6. #include <UReanimator.h>
  7. #include <URegistrar.h>
  8. #include <LStream.h>
  9. #include <LTabGroup.h>
  10. #include <UAttachments.h>
  11. #include <LStaticText.h>
  12. #include <LAMStaticTextImp.h>
  13. #include <LGAStaticTextImp.h>
  14. #include <LEditText.h>
  15. #include <LAMEditTextImp.h>
  16. #include <LGAEditTextImp.h>
  17. #include <LSlider.h>
  18. #include <LAMTrackActionImp.h>
  19. #include <LGASliderImp.h>
  20. #include <CustomControls.h>
  21. #include <CTextUtils.h>
  22.  
  23. #include "DDocData.h"
  24. #include "TemperatureCmds.h"
  25.  
  26. const MessageT    msgEditCentigrade    = 'Edie';
  27. const MessageT    msgEditFahrenheit    = 'Edit';
  28. const MessageT    msgCentSlider    = 'Cenr';
  29.  
  30. #define PPob_MainWindowID    201
  31. #define RidL_MainWindowID    201
  32.  
  33. Boolean        CMainWindow::sIsRegistered = false;
  34.  
  35. //----------
  36. CMainWindow*        CMainWindow::CreateMainWindow (
  37.     LCommander*        inSuperCommander,
  38.     DDocData*        inData)
  39. {
  40.     if (!sIsRegistered) {
  41.         RegisterClass ();
  42.     }
  43.  
  44.     CMainWindow*        window;
  45.     window = (CMainWindow *)LWindow::CreateWindow(PPob_MainWindowID, inSuperCommander);
  46.     window->ConnectToData (inData);
  47.     return window;
  48. }
  49.  
  50. //----------
  51. #define    RegisterClasses(AbstractClass,AMImpClass,GAImpClass)    \
  52.     RegisterClass_(AbstractClass);    \
  53.     if (useAppearance) {    \
  54.         RegisterClassID_(AMImpClass, AbstractClass::imp_class_ID);    \
  55.     } else {    \
  56.         RegisterClassID_(GAImpClass, AbstractClass::imp_class_ID);    \
  57.     }
  58.  
  59. //----------
  60. void    CMainWindow::RegisterClass ()
  61. {
  62.     Boolean        useAppearance = UEnvironment::HasFeature (env_HasAppearance);
  63.  
  64.     RegisterClass_(CMainWindow);
  65.  
  66.     // register the pane classes we use
  67.     RegisterClasses (LStaticText, LAMStaticTextImp, LGAStaticTextImp);
  68.     RegisterClasses (LEditText, LAMEditTextImp, LGAEditTextImp);
  69.     RegisterClasses (LSlider, LAMTrackActionImp, LGASliderImp);
  70.     RegisterClasses (CControlPane, CustomControlImp, CustomControlImp);
  71.  
  72.     sIsRegistered = true;
  73. }
  74.  
  75. //----------
  76. CMainWindow::CMainWindow (
  77.     LStream*    inStream)
  78.     : LWindow (inStream)
  79. {
  80. }
  81.  
  82. //----------
  83. CMainWindow::~CMainWindow ()
  84. {
  85. }
  86.  
  87. //----------
  88. //    This member function gets called once the containment hierarchy that contains
  89. //    this pane has been built. It gives us a chance to get data members for
  90. //    interesting subviews, and to do other operations now that our subviews exist.
  91. void    CMainWindow::FinishCreateSelf ()
  92. {
  93.     mEditCentigradeField = (LEditText*) FindPaneByID ('Edie');
  94.     mEditCentigradeField->AddListener (this);
  95.  
  96.     mEditFahrenheitField = (LEditText*) FindPaneByID ('Edit');
  97.     mEditFahrenheitField->AddListener (this);
  98.  
  99.     mCentSliderScroll = (LSlider*) FindPaneByID ('Cenr');
  100.  
  101.     mFahrBarBar = (CControlPane*) FindPaneByID ('Fahr');
  102.  
  103.  
  104.     LTabGroup*        tabGroup = new LTabGroup(this);
  105.     mEditCentigradeField->SetSuperCommander(tabGroup);    // becomes the active field
  106.     mEditFahrenheitField->SetSuperCommander(tabGroup);
  107.  
  108.     UReanimator::LinkListenerToControls(this, this, RidL_MainWindowID);
  109.         // "connect" self to our controls that we want to "listen" to
  110.  
  111.     // any additional initialization for your window:
  112. }
  113.  
  114. //----------
  115. void    CMainWindow::ConnectToData (
  116.     DDocData*        inData)
  117. {
  118.     mData = inData;
  119.     mData->AddListener (this);
  120.  
  121.     mEditCentigradeField->SetValue (mData->GetCentigrade ());
  122.     mEditFahrenheitField->SetValue (mData->GetFahrenheit ());
  123.     mCentSliderScroll->SetValue (mData->GetCentigrade ());
  124.     mFahrBarBar->SetValue (mData->GetFahrenheit ());
  125. }
  126.  
  127. //----------
  128. void    CMainWindow::DataChanged (
  129.     long        inDataID)
  130. {
  131.     StopListening ();
  132.  
  133.     if (inDataID == idCentigrade) {
  134.         if (!mEditCentigradeField->IsTarget ()) {
  135.             mEditCentigradeField->SetValue (mData->GetCentigrade ());
  136.         }
  137.     }
  138.     if (inDataID == idFahrenheit) {
  139.         if (!mEditFahrenheitField->IsTarget ()) {
  140.             mEditFahrenheitField->SetValue (mData->GetFahrenheit ());
  141.         }
  142.     }
  143.     if (inDataID == idCentigrade) {
  144.         mCentSliderScroll->SetValue (mData->GetCentigrade ());
  145.     }
  146.     if (inDataID == idFahrenheit) {
  147.         mFahrBarBar->SetValue (mData->GetFahrenheit ());
  148.     }
  149.  
  150.     StartListening ();
  151. }
  152.  
  153. //----------
  154. void    CMainWindow::ListenToMessage (
  155.     MessageT    inMessage,
  156.     void*        ioParam)
  157. {
  158.     switch (inMessage) {
  159.     case msgDataChanged:
  160.             DataChanged ((long)ioParam);
  161.         break;
  162.  
  163.     case msgEditCentigrade:
  164.             mData->SetCentigrade (mEditCentigradeField->GetValue ());
  165.         break;
  166.  
  167.     case msgEditFahrenheit:
  168.             mData->SetFahrenheit (mEditFahrenheitField->GetValue ());
  169.         break;
  170.  
  171.     case msgCentSlider:
  172.             mData->SetCentigrade (mCentSliderScroll->GetValue ());
  173.         break;
  174.  
  175.     default:
  176.           ; // do something
  177.         break;
  178.     }
  179. }
  180.  
  181. //----------
  182. Boolean        CMainWindow::ObeyCommand (
  183.     CommandT    inCommand,
  184.     void*        ioParam)
  185. {
  186.     Boolean        cmdHandled = true;
  187.  
  188.     if (inCommand < 0) {
  189.         // modal dialog has finished
  190.  
  191.         switch (-inCommand) {
  192.         }
  193.  
  194.     } else {
  195.         switch (inCommand) {
  196.  
  197.         default:
  198.                 cmdHandled = LWindow::ObeyCommand(inCommand, ioParam);
  199.             break;
  200.         }
  201.     }
  202.  
  203.     return cmdHandled;
  204. }
  205.  
  206. //----------
  207. void    CMainWindow::FindCommandStatus (
  208.     CommandT    inCommand,
  209.     Boolean        &outEnabled,
  210.     Boolean        &outUsesMark,
  211.     Char16        &outMark,
  212.     Str255        outName)
  213. {
  214.     outUsesMark = false;
  215.  
  216.     switch (inCommand) {
  217.  
  218.  
  219.     default:
  220.             LWindow::FindCommandStatus(inCommand, outEnabled,
  221.                                         outUsesMark, outMark, outName);
  222.         break;
  223.     }
  224. }
  225.